<!--添加人员控件-->

<template>
    <div class="page-box">

        <div class="page-search">
            <div>
                <label>人员编号</label>
                <el-input v-model="searchForm.PersonCode" style="width: 160px;" placeholder="请输入人员编号"></el-input>
            </div>
            <div>
                <label>人员名称</label>
                <el-input v-model="searchForm.UserName" style="width: 160px;" placeholder="请输入人员名称"></el-input>
            </div>
            <div>
                <el-button type="primary" @click="search">搜索</el-button>
                <el-button @click="reset">重置</el-button>
            </div>
        </div>



        <div class="page-section">
            <el-table :data="tableData" ref="dataForm" v-loading="isLoading" height="360">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column prop="PersonCode" label="人员编号" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="Name" label="人员名称" :show-overflow-tooltip="true"></el-table-column>

            </el-table>


            <Pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"
                :PageIndex="pageDomain.PageIndex" :PageSize="pageDomain.PageSize" :TotalCount="pageDomain.TotalCount" />
        </div>
        <div class="page-box-footer">
            <el-button type="primary" @click="checked">确认选择</el-button>
        </div>


    </div>
</template>
<script>


import Pagination from '@/components/Pagination.vue';
export default {
    props: {
        BomList: {
            type: Array,
            required: true
        }
    },
    components: {
        Pagination
    },
    mounted() {
        this.dataBind();
    },
    data() {
        return {

            //搜索字段
            searchForm: {
                PersonCode: '',
                UserName: '',
            },

            pageDomain: {
                PageIndex: 1,
                PageSize: 10,
                TotalCount: 0
            },
            tableData: [],
            isLoading: false


        }
    },
    methods: {
        checked() {



            //获取选中的每一项

            if (this.$refs.dataForm.selection.length <= 0) {
                this.showNotify('请选择一项');
                return;
            }

            this.$refs.dataForm.selection.map(model => {

                var obj = new Object();
                console.log(model);
                //处理所需字段
                this.$set(obj, 'UserName', model.Name);
                this.$set(obj, 'PersonCode', model.PersonCode);


                this.BomList.push(obj);

            })


            this.$emit('callback');
        },



        search() {
            this.pageDomain.PageIndex = 1;
            this.dataBind();
        },
        reset() {
            this.searchForm.PersonCode = '';
            this.searchForm.UserName = '';
        },

        //获取数据
        dataBind() {
            this.isLoading = true;
            this.$http.get('/api/Team/GetTeamTypeAllAsync',
                {
                    params: {
                        PageIndex: this.pageDomain.PageIndex,
                        PageSize: this.pageDomain.PageSize,
                        PersonCode: this.searchForm.PersonCode,
                        Name: this.searchForm.UserName
                    }
                })
                .then(res => {
                    this.tableData = res.Data;
                    console.log(res.Data)
                    this.pageDomain.TotalCount = res.Count;
                    this.isLoading = false;
                })
        },
        //分页方法
        handleSizeChange(val) {
            this.pageDomain.PageIndex = 1;
            this.pageDomain.PageSize = val;
            this.dataBind();
        },
        handleCurrentChange(val) {
            this.pageDomain.PageIndex = val;
            this.dataBind();
        },



    }
}
</script>